package com.example.mybatisdemo.controller;

import com.dtflys.forest.annotation.Post;
import com.example.mybatisdemo.domain.param.TestParam;
import com.example.mybatisdemo.service.PdfService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/pdf")
public class PdfController {

    @Resource
    private PdfService pdfService;

    @GetMapping("/export")
    public void export(HttpServletResponse response) throws Exception {
        pdfService.exportPdf(response);

    }

    @GetMapping("/test")
    public void test(TestParam param) throws Exception {
        System.out.println(param);

    }

    @PostMapping("/test")
    public void testPost(@RequestParam("file") MultipartFile file) throws Exception {
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getOriginalFilename().lastIndexOf("."));
        String tmpName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        System.out.println(tmpName);
    }

}
